﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace WeatherServiceClient
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private ServiceReference1.GlobalWeatherSoapClient _client;
        public ServiceReference1.GlobalWeatherSoapClient Client
        {
            get
            {
                if (_client == null)
                {
                    _client = new ServiceReference1.GlobalWeatherSoapClient();
                    _client.GetCitiesByCountryCompleted +=new EventHandler<ServiceReference1.GetCitiesByCountryCompletedEventArgs>(_client_GetCitiesByCountryCompleted);
                    _client.GetWeatherCompleted += new EventHandler<ServiceReference1.GetWeatherCompletedEventArgs>(_client_GetWeatherCompleted);
                }
                return _client;
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Client.GetCitiesByCountryAsync("Turkey","test");
             
        }

        void _client_GetWeatherCompleted(object sender, ServiceReference1.GetWeatherCompletedEventArgs e)
        {
            throw new NotImplementedException();
        }
        void _client_GetCitiesByCountryCompleted(object sender, ServiceReference1.GetCitiesByCountryCompletedEventArgs e)
        {
            if (e.Error != null)
                throw e.Error;

            if (e.UserState != null)
            {
                string s = e.UserState as string;
            }

            textBlock1.Text = e.Result;
        }
    }
}
